<template>
    <div>
        <li v-for="(item,key) in mData" :key="key">            
            <a :href="item.link" :class="{'selected':item.isSelected}" @click="selectmenu(mData,item,key)">
                <i class="icon" :class="item.isSelected ? 'show':'notshow'"></i>  
                {{ item.name }}
                <span class="show-icon" v-show="item.children && item.isSelected == false">+</span>
                <span class="show-icon" v-show="item.children && item.isSelected == true">-</span>
            </a>
            <ul :class="{'sm':item.children}">
               <mtree v-show="item.children && item.isSelected == true" :m-data="item.children" @setmenu="selectmenu"></mtree>
            </ul> 
        </li>
    </div>
</template>

<script>
export default {
  name: "mtree",
  props: {
    mData: Array
  },
  data() {
    return {};
  },
  methods: {
    selectmenu(list, item) {
      this.$emit("setmenu", list, item);
    }
  },
  watch: {
    mData(val, oldVal) {
      this.mData = val;
    }
  }
};
</script>

<style scope>
.tree {
  width: 280px;
  background-color: rgb(31, 31, 31);
  padding: 15px;
  box-sizing: border-box;
  font-family: "microsoft yahei";
}
.tree ul{
  padding-left:10px;
}
.tree a {
  color: #dbdbdb;
  display: block;
  width: 100%;
  padding: 0px 5px;
  box-sizing: border-box;
  font-size: 16px;
  margin-bottom: 2px;
}
.tree .icon{
  font-size: 18px;
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: #dbdbdb;
  vertical-align: middle;
  margin-right: 5px;
}
.show{
  visibility:visible;
}
.notshow{
  visibility: hidden;
}
.tree a:hover {
  color: #fff;
}
.tree .show-icon {
  float: right;
  font-weight: bold;
}
.tree .selected {
  /* background-color: #383838; */
}
.tree .sm a {
  font-size: 14px;
}
</style>


